﻿/*
-------------------------------------
    Rodeo Game Engine

    Rodeo Entity Module
    Model3D.h - header file

    Copyright(c) Marcin Goryca
-------------------------------------
*/
#ifndef RODEO_ENTITY_MODEL3D_H_
#define RODEO_ENTITY_MODEL3D_H_

#ifndef RODEO_ENTITY_ENTITY_H_
#include "entity\entity.h"
#endif    //RODEO_ENTITY_ENTITY_H_

#ifndef RODEO_IO_FILE3DFACTORY_H_
#include "io\file3dfactory.h"
#endif    //RODEO_IO_FILE3DFACTORY_H_

#ifndef RODEO_RENDERER_BUFFERS_H_
#include "renderer\buffers.h"
#endif    //RODEO_RENDERER_BUFFERS_H_

#ifndef RODEO_RENDERER_RENDERMODE_H_
#include "renderer\rendermode.h"
#endif    //RODEO_RENDERER_RENDERMODE_H_

namespace rodeoentity
{
class Texture;
class Vector3;
class Model3D : public rodeorenderer::RenderMode, public Entity
{
public:
    Model3D()
        :Entity("", "model3d"),
         mesh_count_(model_.mesh_count_),
         material_count_(model_.material_count_),
         vertex_count_(0),
         index_count_(0),
         winding_(GL_CCW)
    {}

    Model3D(const char* filename, rodeoio::File3DFactory::File3DType type);

    virtual ~Model3D();

    void load(const char* filename, rodeoio::File3DFactory::File3DType type);

    void update();
    void scale(float scale_factor);

    virtual void draw(); 

    rodeocore::ui getMeshCount()const { return mesh_count_; }
    rodeocore::ui getMaterialCount()const { return material_count_; }
    rodeocore::ui getVertexCount()const { return vertex_count_; }
    rodeocore::ui getIndexCount()const { return index_count_; }

    void setMeshCount(rodeocore::ui mc){ mesh_count_ = mc; }
    void setMaterialCount(rodeocore::ui mtc) { material_count_ = mtc; }
    void setVertexCount(rodeocore::ui vc){ vertex_count_ = vc; }
    void setIndexCount(rodeocore::ui ic){ index_count_ = ic; }

    virtual void release();
    virtual void update(float dt);

    void setDefaults();


protected:

    void create();
    void buildAABB();

    void render();

    void bindTexture(rodeocore::ui& texture_id);

//==== MEMBERS ====//
    Model model_;
    rodeorenderer::Buffers buffer_;

    rodeocore::ui texture_id_;
    rodeocore::ui mesh_count_;
    rodeocore::ui material_count_;
    rodeocore::ui vertex_count_;
    rodeocore::ui index_count_;

    bool has_texture_;
    bool has_material_;
    GLenum winding_;
};
}    //end of rodeoentity namespace
#endif    //RODEO_ENTITY_MODEL3D_H_